<?php

namespace App\Resource;

use App\Model\User;
use Hyperf\Resource\Json\ResourceCollection;

class UserCollection extends ResourceCollection
{
    /**
     * Transform the resource collection into an array.
     *
     * @return array
     */
    public function toArray(): array
    {
        return parent::toArray();
    }

    public function toListApi()
    {
        $data = [];
        /** @var User $v */
        foreach ($this as $v) {
            $data[] = [
                'id' => $v->id,
                'nickname' => $v->nickname ?? '',
                'header' => stripslashes(($v->header->url ?? '')),
                'mobile' => $v->mobile ?? '',
                'status' => $v->status ?? -1,
                'status_text' => $v->status_text,
                'is_enterprise_certification' => $v->is_enterprise_certification ?? -1,
                'is_enterprise_certification_text' => $v->is_enterprise_certification == 1 ? '已认证' : '未认证',
                'enterprise' => $v->enterprise->name ?? '',
                'create_time' => $v->create_time ? $v->create_time->toDateTimeString() : '',
            ];
        }

        return $data;
    }
}
